package com.sixkey.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixkey.annotation.OperationLog;
import com.sixkey.constant.CommonConstant;
import com.sixkey.entity.Evaluation;
import com.sixkey.entity.Feedback;
import com.sixkey.entity.vo.EvaluationVo;
import com.sixkey.entity.vo.FeedbackVo;
import com.sixkey.response.Response;
import com.sixkey.service.IFeedbackService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-10-18
 */

/**
 * 用户反馈
 */

@Slf4j
@Validated
@CrossOrigin
@RestController
@RequestMapping("/feedback")
@RequiredArgsConstructor
public class FeedbackController {

    private final IFeedbackService feedbackService;

    /**
     * 后台用户反馈分页查询
     * @param
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response list(@PathVariable("pageNo") Integer pageNo,
                         @PathVariable("pageSize") Integer pageSize,
                         FeedbackVo feedbackVo){
        log.info("后台用户反馈分页查询请求进来~");
        Page<Feedback> list = feedbackService.queryList(pageNo,pageSize,feedbackVo);
        return Response.success(list);
    }

    /**
     * 用户反馈数据保存
     * @param
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody @Valid Feedback feedback){
        log.info("用户反馈数据保存请求进来~");
        feedbackService.save(feedback);
        return Response.success();
    }

    /**
     * 管理员回复
     * @param
     * @return
     */
    @OperationLog(value = "管理员回复")
    @PutMapping("/update")
    public Response update(@RequestBody @Valid Feedback feedback){
        log.info("管理员回复请求进来~~~~");
        feedback.setStatus(CommonConstant.FEED_BACK_REPLY_STATUS);
        feedbackService.updateById(feedback);
        return Response.success();
    }

    /**
     * 管理员回复
     * @param
     * @return
     */
    @GetMapping("/echo/{id}")
    public Response getFeedBackById(@PathVariable("id") Integer id){
        log.info("管理员回复请求进来~~~~");
        Feedback feedback = feedbackService.getById(id);
        return Response.success(feedback);
    }

    /**
     * 用户反馈删除
     * @param
     * @return
     */
    @OperationLog(value = "用户反馈删除")
    @DeleteMapping("/remove/{id}")
    public Response remove(@PathVariable("id") List<Integer> id){
        log.info("用户反馈删除请求进来~~~~");
        feedbackService.removeBatchByIds(id);
        return Response.success();
    }
}
